import cv2

filename = r'E:\python\data\lena.jpg'
img = cv2.imread(filename, 0)

# Sobel算子边缘检测
sobel = cv2.Sobel(img, cv2.CV_16S, 1,0, ksize =3)
# Laplacian边缘检测
laplacian = cv2.Laplacian(img, cv2.CV_16S)
# Canny边缘检测，最小阈值50，最大阈值120
canny = cv2.Canny(img, 50, 120)

sobel_show = cv2.convertScaleAbs(sobel)
lap_show = cv2.convertScaleAbs(laplacian)
cv2.imshow('Image', img)
cv2.imshow('Sobel', sobel_show)
cv2.imshow('Laplician', lap_show)
# 显示Canny边缘检测结果
cv2.imshow('Canny', canny)


cv2.waitKey()
cv2.destroyAllWindows()